package tt.com.deadcold.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.SneakyThrows;
import org.springframework.data.relational.core.sql.Between;
import org.springframework.stereotype.Service;
import tt.com.common.enums.Status;
import tt.com.common.model.DeadColdRoom;
import tt.com.common.util.CommonResult;
import tt.com.deadcold.mapper.DeadColdMapper;
import tt.com.deadcold.service.ColdMoney;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Service
public class ColdMoneyImpl implements ColdMoney {

    @SneakyThrows
    @Override
    public CommonResult costcalculation(DeadColdRoom deadColdRoom) {
        //入藏时间
        Date enterColdTime = deadColdRoom.getEnterColdTime();
        //出藏时间
        Date comeColdTime = deadColdRoom.getComeColdTime();

        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time1 = dfs.format(enterColdTime);
        String time2 = dfs.format(comeColdTime);
        Date begin = dfs.parse(time1);
        Date end = dfs.parse(time2);
        long totaltime = (end.getTime() - begin.getTime()) / 60;
        //存了多少天
        long daytime = totaltime / 24;
        //总共入藏了多久的时间
        long lasttime = totaltime / 60;
        if (lasttime < 24 && lasttime > 0) {
            deadColdRoom.setColdPrice(BigDecimal.valueOf(10));
        } else if (lasttime > 24) {
            deadColdRoom.setColdPrice(BigDecimal.valueOf(daytime * 10));
        } else
            return CommonResult.buildR(Status.DEFAULT, "时间格式有误");
        return CommonResult.buildR(Status.OK, "计算成功");
    }
}
